package com.rotsel.mh3udb.app.Activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.rotsel.mh3udb.app.Adapters.IdNameAdapter;
import com.rotsel.mh3udb.app.ListModels.IdNameModel;
import com.rotsel.mh3udb.app.R;
import com.rotsel.mh3udb.app.lists.WeaponList;
import com.rotsel.mh3udb.app.lists.WeaponTypeList;

import java.util.ArrayList;

/**
 * Created by rots on 31.01.14.
 */
public class WeaponListActivity extends BaseActivity {
    private ListView weaponList;

    @Override
    public void onCreate(Bundle savedInstanceState){
        Log.d("dev", "Starting weapon list activity...");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);

        Bundle extras = getIntent().getExtras();
        int weaponTypeId = extras.getInt("weaponTypeId");
        Log.d("dev", "Weapon type id: " + weaponTypeId);
        setTitle(getDb().getWeaponTypeNameById(weaponTypeId));

        weaponList = (ListView)findViewById(R.id.list);
        ArrayList<IdNameModel> listWeaponsByWpnTypeId = getDb().getListWeaponsByWpnTypeId(weaponTypeId);
        IdNameAdapter adapter = new IdNameAdapter(this, listWeaponsByWpnTypeId);
        weaponList.setAdapter(adapter);

        weaponList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.d("dev", "Clicked Weapon Type item - position: " + position + " id: " + id);
                Log.d("dev", "Creating weapon type intent...");
                Intent intent = new Intent(WeaponListActivity.this, WeaponDetailsActivity.class);
                Bundle b = new Bundle();
                b.putInt("weaponId", (int)id);
                intent.putExtras(b);
                Log.d("dev", "Weapon type intent created");
                startActivity(intent);
            }
        });
    }
}
